/**
 * Created by vincent on 2017/9/26.
 */
moduleForum.controller("ForumReplyQuery", function (LanguageService, $scope, $state, $stateParams, $log, $timeout, LoadingService, DialogService, ConstantService, EnumService, ForumReplyResource) {
    initPage($scope);
    $scope.$on("$viewContentLoaded", function () {
        ConstantService.addState($state.current, true, LanguageService.language('评论回复管理'));
        getForumReplyList();
        $scope.user = ConstantService.getItem('user');
    });

    var getForumReplyList = function () {
        //LoadingService.show();
        $scope.forumId = $stateParams.forumId;
        ForumReplyResource.findListByForumId({forumId: $scope.forumId}, function (replyResult) {
            $log.debug("评论下回复列表", replyResult);
            $scope.replyList = replyResult;
            //LoadingService.hide();
        });
    };

    $scope.refreshForumReply = function () {
        getForumReplyList();
    };

    $scope.setReplyValid = function (reply) {
        Alert.confirm(function () {
            //LoadingService.show();
            ForumReplyResource.setValid(reply, function (replyResult) {
                $log.debug("设为有效结果", replyResult);
                angular.copy(replyResult, reply);
                $timeout(function () {
                    //LoadingService.hide();
                    Alert.success();
                }, 300);
            }, function () {
                //LoadingService.hide();
            });
        });
    };

    $scope.setReplyInvalid = function (reply) {
        Alert.confirm(function () {
            //LoadingService.show();
            ForumReplyResource.setInvalid(reply, function (replyResult) {
                $log.debug("设为无效结果", replyResult);
                angular.copy(replyResult, reply);
                $timeout(function () {
                    //LoadingService.hide();
                    Alert.success();
                }, 300);
            }, function () {
                //LoadingService.hide();
            });
        });
    };

});